package com.qding.park.manager.service.statis.facade.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import com.qding.park.common.core.constant.MongodbConstant;
import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.utils.DateUtils;
import com.qding.park.common.utils.ListUtil;
import com.qding.park.manager.common.pojo.ParkDataResult;
import com.qding.park.manager.facade.statis.service.InoutcheckStatisFacade;
import com.qding.park.manager.pojo.enums.OrderSourceEnum;
import com.qding.park.manager.pojo.example.NcPresenExample;
import com.qding.park.manager.pojo.example.TbOutcheckExample;
import com.qding.park.manager.pojo.noncore.NcParkInoutInfo;

/**
 * @ClassName: InoutcheckStatisFacadeImpl
 * @Description: 进出场统计接口
 * @author Comsys-Administrator
 * @date 2016年10月10日 上午9:41:28
 *
 */
@Service("inoutcheckStatisFacade")
public class InoutcheckStatisFacadeImpl implements InoutcheckStatisFacade {
    private static final Logger _log = LoggerFactory.getLogger(InoutcheckStatisFacadeImpl.class); 
	@Autowired
	private MongoTemplate mongoTemplate;

	/*
	 * <p>Title: presen</p> <p>Description: 车辆在场统计查询</p>
	 * 
	 * @param example
	 * 
	 * @param jumpPage
	 * 
	 * @param pageLength
	 * 
	 * @return
	 * 
	 * @throws BaseException
	 * 
	 * @see com.qding.park.manager.facade.statis.service.InoutcheckStatisFacade#
	 * presen(com.qding.park.manager.pojo.example.NcInoutcheckExample, int, int)
	 */
	// @Override
	// public ParkDataResult presen(NcInoutcheckExample example, int jumpPage,
	// int pageLength) throws BaseException {
	//
	// // 车辆进场记录表
	// DBCollection collection =
	// mongoTemplate.getCollection(MongodbConstant.TABLENAME_CHECKIN);
	//
	// // collection.
	// // DBObject command=new BasicDBObject();
	// // command.put("distinct", "checkin");
	// // command.put("key", "enInID");
	// // CommandResult result=mongoTemplate.executeCommand(command);
	// //// result.
	// ParkDataResult parkDataResult = ParkDataResult.createEmpty();
	// return parkDataResult;
	// }

//	@Override
	public ParkDataResult out_bank(TbOutcheckExample example, int jumpPage, int pageLength) throws BaseException {

		String tablename_inoutcheck = MongodbConstant.TABLENAME_CHECKINOUT;

		Criteria matchCrieria = new Criteria();
		matchCrieria.where("_id").not();
		if (example.getStartTime() != null && example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()),
					Criteria.where("outTime").lte(example.getEndTime()));
		} else if (example.getStartTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()));
		} else if (example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").lte(example.getEndTime()));
		}
		if (example.getCarNum() != null) {
			matchCrieria.and("carNum").is(example.getCarNum());
		}
		if (!StringUtils.isBlank(example.getParkId())) {
			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
		}
		if (!StringUtils.isBlank(example.getCardType())) {
			matchCrieria.and("cardType").is(Integer.valueOf(example.getCardType()));
		}
		if (!StringUtils.isBlank(example.getOpType())) {
			matchCrieria.and("opType").is(Integer.valueOf(example.getOpType()));
		}

		Criteria whereCriteria = new Criteria();
		if (!StringUtils.isBlank(example.getParkingTime())) {
			matchCrieria.and("parkingTime").gt(Integer.valueOf(example.getParkingTime())*60*1000);
		}

//		List<NcParkInoutInfo> ncParkInoutInfoList = mongoTemplate.find(Query.query(matchCrieria),
//				NcParkInoutInfo.class);

		StringBuffer projectJsonStr = new StringBuffer();
		projectJsonStr.append("{ ");
		projectJsonStr.append("  supplyID : 1, ");
		projectJsonStr.append("  parkCode :1, ");
		projectJsonStr.append("  parkId : 1, ");
		projectJsonStr.append(" cardCode : 1, ");
		projectJsonStr.append("  carNum :1, ");
		projectJsonStr.append(" enInID : 1, ");
		projectJsonStr.append(" enterTime : 1, ");
		projectJsonStr.append(" roomName :1, ");
		projectJsonStr.append(" opType : 1, ");
		projectJsonStr.append(" opSpecial : 1, ");
		projectJsonStr.append(" cardType : 1, ");
		projectJsonStr.append(" carType : 1, ");
		projectJsonStr.append(" shouldFeeMoney : 1,");
		projectJsonStr.append(" feeMoney : 1, ");
		projectJsonStr.append(" create_time :1, ");
		projectJsonStr.append(" enOutID : 1, ");
		projectJsonStr.append(" outTime : 1, ");
		projectJsonStr.append(" payOrderID : 1, ");
		projectJsonStr.append("  outRoomName : 1,");
		projectJsonStr.append("parkingTime:{$subtract:[\"$outTime\",\"$enterTime\"]} ");
		projectJsonStr.append("} ");
		
		final DBObject project = new BasicDBObject("$project", JSON.parse(projectJsonStr.toString()));

		Aggregation agg = Aggregation.newAggregation(Aggregation.match(Criteria.where("outTime").exists(true)),
				new AggregationOperation() {

					@Override
					public DBObject toDBObject(AggregationOperationContext context) {
						return project;
					}

				},
			  Aggregation.match(matchCrieria),
			  Aggregation.sort(new Sort(Direction.DESC, "outTime")),
			  Aggregation.skip((jumpPage - 1) * pageLength), Aggregation.limit(pageLength));
		
		Aggregation aggTotal = Aggregation.newAggregation(Aggregation.match(Criteria.where("outTime").exists(true)),
				new AggregationOperation() {

					@Override
					public DBObject toDBObject(AggregationOperationContext context) {
						return project;
					}

				},
			  Aggregation.match(matchCrieria));
			_log.info(aggTotal.toString());
			_log.info(agg.toString());
		
		AggregationResults<NcParkInoutInfo> resultsPage =mongoTemplate.aggregate(agg, tablename_inoutcheck, NcParkInoutInfo.class);
		AggregationResults<NcParkInoutInfo> resultsTotal = mongoTemplate.aggregate(aggTotal, tablename_inoutcheck,
				NcParkInoutInfo.class);
		long total = resultsTotal.getMappedResults().size();
		List<NcParkInoutInfo> list = resultsPage.getMappedResults();
		List dataList = new ArrayList();
		int totalFee=0;
		for (NcParkInoutInfo info : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("carNum", info.getCarNum());
			map.put("inPortName", info.getRoomName());
			map.put("inCheckTime", DateUtils.formatDate(info.getEnterTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("inCheckPhoto", "");
			map.put("outPortName", info.getOutRoomName());
			map.put("outCheckTime", DateUtils.formatDate(info.getOutTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("cardType", info.getCardType());
			map.put("parkingFee", info.getFeeMoney());
			map.put("payType", StringUtils.isBlank(info.getPayOrderID())?"线下":"线上");
			map.put("allowType", info.getOpType());
			map.put("inParkTime", DateUtils.getDatePoor(info.getOutTime(),info.getEnterTime()));
			totalFee=totalFee+info.getFeeMoney();
			dataList.add(map);
		}
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("list", dataList);
		data.put("currentPage", jumpPage);
		data.put("numPerPage", pageLength);
		data.put("totalCount", total);
		data.put("hast", jumpPage > 1 ? true : false);
		data.put("next", jumpPage * pageLength < total ? true : false);
		data.put("totalFee", totalFee);

		ParkDataResult parkDataResult = ParkDataResult.createObjDate();
		parkDataResult.putMapOnObj(data);
		return parkDataResult;
	}
	
	
	@Override
	public ParkDataResult out(TbOutcheckExample example, int jumpPage, int pageLength) throws BaseException {

		String tablename_outcheck = MongodbConstant.TABLENAME_CHECKOUT;

		Criteria matchCrieria = new Criteria();
		matchCrieria.where("_id").not();
		if (example.getStartTime() != null && example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()),
					Criteria.where("outTime").lte(example.getEndTime()));
		} else if (example.getStartTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()));
		} else if (example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").lte(example.getEndTime()));
		}
		if (example.getCarNum() != null) {
			//改成模糊查询
//			matchCrieria.and("carNum").is(example.getCarNum());
			matchCrieria.and("carNum").regex(".*"+example.getCarNum()+".*");
		}
		if (!StringUtils.isBlank(example.getParkId())&&!ListUtil.isEmpty(example.getInParks())) {
//			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
			matchCrieria.andOperator(Criteria.where("parkId").is(Integer.valueOf(example.getParkId())),
					Criteria.where("parkId").in(example.getInParks()));
		}else if(!StringUtils.isBlank(example.getParkId())){
			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
		}else if(!ListUtil.isEmpty(example.getInParks())){
			matchCrieria.and("parkId").in(example.getInParks());
		}
		
		
		if (!StringUtils.isBlank(example.getCardType())) {
			matchCrieria.and("cardType").is(Integer.valueOf(example.getCardType()));
		}
		if (!StringUtils.isBlank(example.getOpType())) {
			matchCrieria.and("opType").is(Integer.valueOf(example.getOpType()));
		}

//		Criteria whereCriteria = new Criteria();
		if (!StringUtils.isBlank(example.getParkingTime())) {
			matchCrieria.and("parkingTime").gt(Integer.valueOf(example.getParkingTime())*60*1000);
		}
		if (!StringUtils.isBlank(example.getParkingFee())) {
			matchCrieria.and("feeMoney").is(Integer.valueOf(example.getParkingFee()));
		}

//		List<NcParkInoutInfo> ncParkInoutInfoList = mongoTemplate.find(Query.query(matchCrieria),
//				NcParkInoutInfo.class);

		StringBuffer projectJsonStr = new StringBuffer();
		projectJsonStr.append("{ ");
		projectJsonStr.append("  supplyID : 1, ");
		projectJsonStr.append("  parkCode :1, ");
		projectJsonStr.append("  parkId : 1, ");
		projectJsonStr.append(" cardCode : 1, ");
		projectJsonStr.append("  carNum :1, ");
		projectJsonStr.append(" enInID : 1, ");
		projectJsonStr.append(" tel : 1, ");
		projectJsonStr.append(" cardName : 1, ");
		projectJsonStr.append(" memberName : 1, ");
		projectJsonStr.append(" enterTime : 1, ");
		projectJsonStr.append(" roomName :1, ");
		projectJsonStr.append(" opType : 1, ");
		projectJsonStr.append(" opSpecial : 1, ");
		projectJsonStr.append(" cardType : 1, ");
		projectJsonStr.append(" carType : 1, ");
		projectJsonStr.append(" shouldFeeMoney : 1,");
		projectJsonStr.append(" feeMoney : 1, ");
		projectJsonStr.append(" create_time :1, ");
		projectJsonStr.append(" enOutID : 1, ");
		projectJsonStr.append(" outTime : 1, ");
		projectJsonStr.append(" operator : 1, ");
		projectJsonStr.append(" parkInPic : 1, ");
		projectJsonStr.append(" parkOutPic : 1, ");
		projectJsonStr.append(" orderSource : 1, ");
//		projectJsonStr.append(" payOrderID : 1, ");
		projectJsonStr.append("  outRoomName : 1,");
		projectJsonStr.append("parkingTime:{$subtract:[\"$outTime\",\"$enterTime\"]} ");
		projectJsonStr.append("} ");
		
		final DBObject project = new BasicDBObject("$project", JSON.parse(projectJsonStr.toString()));

		Aggregation agg = Aggregation.newAggregation(Aggregation.match(Criteria.where("outTime").exists(true)),
				new AggregationOperation() {

					@Override
					public DBObject toDBObject(AggregationOperationContext context) {
						return project;
					}

				},
			  Aggregation.match(matchCrieria),
			  Aggregation.sort(new Sort(Direction.DESC, "outTime")),
			  Aggregation.skip((jumpPage - 1) * pageLength), Aggregation.limit(pageLength));
		
//		Aggregation aggTotal = Aggregation.newAggregation(Aggregation.match(Criteria.where("outTime").exists(true)),
//				new AggregationOperation() {
//
//					@Override
//					public DBObject toDBObject(AggregationOperationContext context) {
//						return project;
//					}
//
//				},
//			  Aggregation.match(matchCrieria));
			_log.info(agg.toString());
			
		Criteria totalCriteria=new Criteria();
		totalCriteria.and("outTime").exists(true);
		Query totalQuery=new Query(totalCriteria);
		long total=mongoTemplate.count(totalQuery, tablename_outcheck);
		
		AggregationResults<NcParkInoutInfo> resultsPage =mongoTemplate.aggregate(agg, tablename_outcheck, NcParkInoutInfo.class);
//		AggregationResults<NcParkInoutInfo> resultsTotal = mongoTemplate.aggregate(aggTotal, tablename_outcheck,
//				NcParkInoutInfo.class);
//		long total = resultsTotal.getMappedResults().size();
		List<NcParkInoutInfo> list = resultsPage.getMappedResults();
		List dataList = new ArrayList();
		int totalFee=0;
		for (NcParkInoutInfo info : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("carNum", info.getCarNum());
			map.put("carNumAttr", info.getCardName());
			map.put("memberName", info.getMemberName()==null?"":info.getMemberName());
			map.put("tel", info.getTel()==null?"":info.getTel());
			map.put("carType", info.getCarType());
			map.put("opSpecial", info.getOpSpecial());
			map.put("operator", info.getOperator()==null?"":info.getOperator());
			map.put("shouldFee", info.getShouldFeeMoney());
			map.put("inPortName", info.getRoomName()==null?"":info.getRoomName());
			map.put("inCheckTime", DateUtils.formatDate(info.getEnterTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("inCheckPhoto",  StringUtils.isBlank(info.getParkInPic())?"":example.getFileDomain()+"/"+info.getParkInPic());
			map.put("outCheckPhoto",StringUtils.isBlank(info.getParkOutPic())?"":example.getFileDomain()+"/"+info.getParkOutPic());
			map.put("outPortName", info.getOutRoomName()==null?"":info.getOutRoomName());
			map.put("outCheckTime", DateUtils.formatDate(info.getOutTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("feeTime", DateUtils.formatDate(info.getOutTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("cardType", info.getCardType());
			map.put("parkingFee", info.getFeeMoney());
//			map.put("payType", StringUtils.isBlank(info.getPayOrderID())?"线下":"线上");
			map.put("payType", OrderSourceEnum.getDescByCode(info.getOrderSource()));
			map.put("allowType", info.getOpType());
			map.put("inParkTime", DateUtils.getDatePoor(info.getOutTime(),info.getEnterTime()));
			totalFee=totalFee+info.getFeeMoney();
			dataList.add(map);
		}
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("list", dataList);
		data.put("currentPage", jumpPage);
		data.put("numPerPage", pageLength);
		data.put("totalCount", total);
		data.put("hast", jumpPage > 1 ? true : false);
		data.put("next", jumpPage * pageLength < total ? true : false);
		data.put("totalFee", totalFee);

		ParkDataResult parkDataResult = ParkDataResult.createObjDate();
		parkDataResult.putMapOnObj(data);
		return parkDataResult;
	}

	@Override
	public List<NcParkInoutInfo> out_exportExcel(TbOutcheckExample  example ) {
		String tablename_outcheck = MongodbConstant.TABLENAME_CHECKOUT;
		Criteria matchCrieria = new Criteria();
//		matchCrieria.where("_id").not();
		if (example.getStartTime() != null && example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()),
					Criteria.where("outTime").lte(example.getEndTime()));
		} else if (example.getStartTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").gte(example.getStartTime()));
		} else if (example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("outTime").lte(example.getEndTime()));
		}
		
//		if (!StringUtils.isBlank(example.getParkId())) {
//			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
//		}
		if (!StringUtils.isBlank(example.getParkId())&&!ListUtil.isEmpty(example.getInParks())) {
//			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
			matchCrieria.andOperator(Criteria.where("parkId").is(Integer.valueOf(example.getParkId())),
					Criteria.where("parkId").in(example.getInParks()));
		}else if(!StringUtils.isBlank(example.getParkId())){
			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
		}else if(!ListUtil.isEmpty(example.getInParks())){
			matchCrieria.and("parkId").in(example.getInParks());
		}
		matchCrieria.and("outTime").exists(true);
		Query query=Query.query(matchCrieria).with(new Sort(new Order(Direction.DESC,"outTime")));
		List<NcParkInoutInfo>  ncParkInoutInfoList=mongoTemplate.find(query, NcParkInoutInfo.class, tablename_outcheck);

		return ncParkInoutInfoList;
	}

	@Override
	public ParkDataResult presen(NcPresenExample example, int jumpPage, int pageLength) throws BaseException {
		// TODO Auto-generated method stub
		String tablename_inoutcheck = MongodbConstant.TABLENAME_CHECKINOUT;

		Criteria matchCrieria = new Criteria();
//		matchCrieria.where("_id").not();
		if (example.getStartTime() != null && example.getEndTime() != null) {
			// matchCrieria.and("enterTime").gte(example.getStartTime());
			matchCrieria.andOperator(Criteria.where("enterTime").gte(example.getStartTime()),
					Criteria.where("enterTime").lte(example.getEndTime()));
		} else if (example.getStartTime() != null) {
			matchCrieria.andOperator(Criteria.where("enterTime").gte(example.getStartTime()));
		} else if (example.getEndTime() != null) {
			matchCrieria.andOperator(Criteria.where("enterTime").lte(example.getEndTime()));
		}
		if (example.getCarNum() != null) {
//			matchCrieria.and("carNum").is(example.getCarNum());
			matchCrieria.and("carNum").regex(".*"+example.getCarNum()+".*");
		}
		
		if ((example.getParkId() != -1)&&!ListUtil.isEmpty(example.getInParks())) {
			matchCrieria.andOperator(Criteria.where("parkId").is(Integer.valueOf(example.getParkId())),
					Criteria.where("parkId").in(example.getInParks()));
		}else if((example.getParkId() != -1)){
			matchCrieria.and("parkId").is(Integer.valueOf(example.getParkId()));
		}else if(!ListUtil.isEmpty(example.getInParks())){
			matchCrieria.and("parkId").in(example.getInParks());
		}
		
		if (example.getCardType() != -1) {
			matchCrieria.and("cardType").is(example.getCardType());
		}
		if (example.getCarType() != -1) {
			matchCrieria.and("carType").is(example.getCarType());
		}

		System.out.println(matchCrieria.getCriteriaObject().toString());
		// long total =mongoTemplate.count(new Query(matchCrieria),
		// tablename_inoutcheck);

		StringBuffer groupJsonStr = new StringBuffer();
		groupJsonStr.append("{                                        ");
		groupJsonStr.append("   _id:\"$carNum\",                       ");
		groupJsonStr.append("   supplyID:{$first:\"$supplyID\"},       ");
		groupJsonStr.append("   parkCode:{$first:\"$parkCode\"},       ");
		groupJsonStr.append("   parkId:{$first:\"$parkId\"},       ");
		groupJsonStr.append("   tel:{$first:\"$tel\"},       ");
		groupJsonStr.append("   memberName:{$first:\"$memberName\"},       ");
		groupJsonStr.append("   cardName:{$first:\"$cardName\"},       ");
		groupJsonStr.append("   cardCode:{$first:\"$cardCode\"},       ");
		groupJsonStr.append("   carNum:{$first:\"$carNum\"},       ");
		groupJsonStr.append("   passID:{$first:\"$passID\"},       ");
		groupJsonStr.append("   enInID:{$first:\"$enInID\"},       ");
		groupJsonStr.append("   enterTime:{$first:\"$enterTime\"},       ");
		groupJsonStr.append("   opType:{$first:\"$opType\"},       ");
		groupJsonStr.append("   opSpecial:{$first:\"$opSpecial\"},       ");
		groupJsonStr.append("   cardType:{$first:\"$cardType\"},       ");
		groupJsonStr.append("   carType:{$first:\"$carType\"},       ");
		groupJsonStr.append("   shouldFeeMoney:{$first:\"$shouldFeeMoney\"},       ");
		groupJsonStr.append("   feeMoney:{$first:\"$feeMoney\"},       ");
		groupJsonStr.append("   create_time:{$first:\"$create_time\"},       ");
		groupJsonStr.append("   enOutID:{$first:\"$enOutID\"},       ");
		groupJsonStr.append("   outTime:{$first:\"$outTime\"},       ");
		groupJsonStr.append("   parkInPic:{$first:\"$parkInPic\"},       ");
		groupJsonStr.append("   outRoomName:{$first:\"$outRoomName\"},       ");
		groupJsonStr.append("   roomName:{$first:\"$roomName\"},       ");
		groupJsonStr.append("   update_time:{$first:\"$update_time\"}       ");
		groupJsonStr.append("}                                        ");
		final DBObject group = new BasicDBObject("$group", JSON.parse(groupJsonStr.toString()));
		_log.info(group.toString());
		// roomName
		 StringBuffer aggTotalGroupJsonStr = new StringBuffer();
		 aggTotalGroupJsonStr.append("{ ");
		 aggTotalGroupJsonStr.append("  _id : 1, ");
		 aggTotalGroupJsonStr.append("  total :{$sum:1} ");
		 aggTotalGroupJsonStr.append("} ");
        final DBObject aggTotalGroup = new BasicDBObject("$group", JSON.parse(aggTotalGroupJsonStr.toString()));
		Aggregation aggTotal = Aggregation.newAggregation(Aggregation.match(matchCrieria),
				Aggregation.sort(new Sort(Direction.DESC, "enterTime")), new AggregationOperation() {
					@Override
					public DBObject toDBObject(AggregationOperationContext context) {
						return group;
					}
				},
				Aggregation.match(new Criteria().and("outTime").is(null)),
				new AggregationOperation() {
                    @Override
                    public DBObject toDBObject(AggregationOperationContext context) {
                        // TODO Auto-generated method stub
                        return aggTotalGroup;
                    }
                }
		        );
		
		Aggregation aggpage = Aggregation.newAggregation(Aggregation.match(matchCrieria),
				Aggregation.sort(new Sort(Direction.DESC, "enterTime")), new AggregationOperation() {
					@Override
					public DBObject toDBObject(AggregationOperationContext context) {
						// TODO Auto-generated method stub
						return group;
					}

				}, Aggregation.match(new Criteria().and("outTime").is(null)),
				Aggregation.sort(new Sort(Direction.DESC, "enterTime")),
				Aggregation.skip((jumpPage - 1) * pageLength), Aggregation.limit(pageLength)
				);
		

		AggregationResults<DBObject> resultsTotal = mongoTemplate.aggregate(aggTotal, tablename_inoutcheck,
				DBObject.class);
		AggregationResults<NcParkInoutInfo> resultsPage = mongoTemplate.aggregate(aggpage, tablename_inoutcheck,
				NcParkInoutInfo.class);
		
		List<DBObject> listTotal = resultsTotal.getMappedResults();
		int total=0;
		if(!ListUtil.isEmpty(listTotal)){
		    total = (int) listTotal.get(0).get("total");
		}
		
		List<NcParkInoutInfo> list = resultsPage.getMappedResults();
		List dataList = new ArrayList();
		for (NcParkInoutInfo info : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("carNum", info.getCarNum());
			map.put("cardType", info.getCardType());
			map.put("inPortName", info.getRoomName());
			map.put("inCheckTime", info.getEnterTime()==null?"":DateUtils.formatDate(info.getEnterTime(), DateUtils.DATE_FORMAT_DATETIME));
			map.put("inCheckPhoto", StringUtils.isBlank(info.getParkInPic())?"":example.getFileDomain()+"/"+info.getParkInPic());
			map.put("carNumAttr", info.getCardName());
			map.put("memberName", info.getMemberName()==null?"":info.getMemberName());
			map.put("tel", info.getTel()==null?"":info.getTel());
			map.put("inCheckChannel", info.getPassID());
			dataList.add(map);
		}
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("list", dataList);
		data.put("currentPage", jumpPage);
		data.put("numPerPage", pageLength);
		data.put("totalCount", total);
		data.put("hast", jumpPage > 1 ? true : false);
		data.put("next", jumpPage * pageLength < total ? true : false);

		ParkDataResult parkDataResult = ParkDataResult.createObjDate();
		parkDataResult.putMapOnObj(data);
		return parkDataResult;
	}

}
